package com.nut.course.api.biz;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.course.api.req.CourseCheckReq;
import com.nut.course.common.Holder;
import com.nut.course.common.Result;
import com.nut.course.entity.Course;
import com.nut.course.entity.TagUser;
import com.nut.course.interceptor.UserJwt;
import com.nut.course.service.CourseService;
import com.nut.course.service.TagUserService;
import com.nut.course.service.UserService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    //课程分页列表
    @GetMapping("list")
    public Result<IPage<Course>> list(
            @RequestParam String userId,
            @RequestParam String departIds,
            @RequestParam String status,
            @RequestParam String name,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) {

        return courseService.list(userId, departIds, status, name, pageNo, pageSize);
    }

    @GetMapping(value = "/{id}")
    public Result<Course> detail(@PathVariable Integer id) {
        return courseService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Course course) {
        return courseService.add(course);
    }

    @PutMapping
    public Result update(@RequestBody Course course) {
        return courseService.updateById(course);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return courseService.deleteByIds(ids);
    }

    @PostMapping("/check")
    public Result check(@RequestBody CourseCheckReq courseCheckReq) {
        return courseService.check(courseCheckReq);
    }

    @GetMapping("/records/{id}")
    public Result records(@PathVariable Integer id) {
        return courseService.records(id);
    }

}
